'Simple Public License (SimPL) 2.0
'The SimPL applies to the software's   source and object code and comes with any rights that I have in it (other than trademarks). You agree to the SimPL by copying, distributing, or making a derivative work of the software.

'You get the royalty free right to:
'   Use the software for any purpose;
'   Make derivative works of it (this is called a 'Derived Work');
'   Copy and distribute it and any Derived Work.

'If you   distribute the software or a Derived Work, you must give back to the community by:
'   Prominently noting the date of any changes you make;
'   Leaving other people's copyright notices, warranty disclaimers, and license terms in place;
'   Providing the source code, build scripts, installation   scripts, and interface definitions in a form that is easy to get and best to modify;

'   Licensing it to everyone under SimPL, or substantially   similar terms (such as GPL 2.0), without adding further restrictions to the rights provided;
'   Conspicuously announcing that it is available under that license.
'
'There are some things that you must shoulder:
'   You get NO WARRANTIES. None of any kind;
'   If the software damages you in any way, you may only recover direct damages   up to the amount you paid for it (that is zero if you did not pay anything). You may not recover any other damages, including those called "consequential damages." (The state or country where you live may not allow you to limit your liability in this way, so this may not apply to you);

'The SimPL continues perpetually, except that   your license rights end automatically if:
'   You do not abide by the "give back to the community" terms (your licensees   get to keep their rights if they abide);
'   Anyone prevents you from   distributing the software under the terms of the SimPL.


Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.ApplicationBlocks.Data

Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Framework.Providers

Namespace Data

  ''' -----------------------------------------------------------------------------
  ''' <summary>
  ''' SQL Server implementation of the abstract DataProvider class
  ''' </summary>
  ''' <remarks>
  ''' </remarks>
  ''' <history>
  ''' </history>
  ''' -----------------------------------------------------------------------------
  Public MustInherit Class SqlDataProvider

    Inherits DataProvider

#Region "Private Members"

    Private Const ProviderType As String = "data"
    Private Const ModuleQualifier As String = "Wazzup_"

    Private _providerConfiguration As ProviderConfiguration = ProviderConfiguration.GetProviderConfiguration(ProviderType)
    Private _connectionString As String
    Private _providerPath As String
    Private _objectQualifier As String
    Private _databaseOwner As String

#End Region

#Region "Constructors"

    Public Sub New()

      ' Read the configuration specific information for this provider
      Dim objProvider As Provider = CType(_providerConfiguration.Providers(_providerConfiguration.DefaultProvider), Provider)

      ' Read the attributes for this provider

      'Get Connection string from web.config
      _connectionString = Config.GetConnectionString("SiteSqlServer")

      If _connectionString = "" Then
        ' Use connection string specified in provider
        _connectionString = objProvider.Attributes("connectionString")
      End If

      _providerPath = objProvider.Attributes("providerPath")

      _objectQualifier = objProvider.Attributes("objectQualifier")
      If _objectQualifier <> "" And _objectQualifier.EndsWith("_") = False Then
        _objectQualifier += "_"
      End If

      _databaseOwner = objProvider.Attributes("databaseOwner")
      If _databaseOwner <> "" And _databaseOwner.EndsWith(".") = False Then
        _databaseOwner += "."
      End If

    End Sub

#End Region

#Region "Properties"

    Public ReadOnly Property ConnectionString() As String
      Get
        Return _connectionString
      End Get
    End Property

    Public ReadOnly Property ProviderPath() As String
      Get
        Return _providerPath
      End Get
    End Property

    Public ReadOnly Property ObjectQualifier() As String
      Get
        Return _objectQualifier
      End Get
    End Property

    Public ReadOnly Property DatabaseOwner() As String
      Get
        Return _databaseOwner
      End Get
    End Property

    Private ReadOnly Property NamePrefix() As String
      Get
        Return DatabaseOwner + ObjectQualifier + ModuleQualifier
      End Get
    End Property

#End Region

#Region "Private Methods"

    Private Function GetFullyQualifiedName(ByVal name As String) As String
      Return DatabaseOwner & ObjectQualifier & ModuleQualifier & name
    End Function

    Private Function GetNull(ByVal Field As Object) As Object
      Return Null.GetNull(Field, DBNull.Value)
    End Function

#End Region

#Region "Public Methods"

    Public Overrides Function GetLatestPosts(SiteID As Integer) As IDataReader
      Return CType(SqlHelper.ExecuteReader(ConnectionString, NamePrefix + "GetLatestPosts", New SqlClient.SqlParameter("@SiteID", SiteID)), IDataReader)
    End Function

#End Region

  End Class

End Namespace